import { plugin, verc, config, data } from '../api/api.js'
import fs from 'node:fs'
import YAML from 'yaml'
import gsCfg from '../../genshin/model/gsCfg.js'
import puppeteer from '../../../lib/puppeteer/puppeteer.js'
import { pluginRoot, pluginResources } from '../model/path.js'
import Reply from '../model/reply.js'
import { createRequire } from 'module';

export class zmStarrySky extends plugin 
{
	constructor () 
	{
    		super
		({
      			name: 'zmStarrySky',
      			dsc: 'zmStarrySky插件',
      			event: 'message',
      			priority: 9,
      			rule:
			[{
        				reg: '(#|\\\*)?(星空帮助)',
        				fnc: 'zmStarrySkyHelp'
      			},{
        				reg: '(#|\\\*)?(境界设定)',
        				fnc: 'zmStarrySkyState'
      			}]
    		})
	}

	async zmStarrySkyHelp () 
	{
//图像操作
		//获取最新require函数方式
		const require = createRequire(import.meta.url);
		//获取puppeteer工具包
		const puppeteer = require('puppeteer');
		//帮助图像异步操作
		(async () => {
  			const browser = await puppeteer.launch();
  			const page = await browser.newPage();
			//确定网页规格
  			await page.setViewport({
				width: 1821,
				height: 3408
			});
			//html生成图
  			await page.goto('file:///E:/Redis-x64-5.0.14.1/Miao-Yunzai/plugins/zm-StarrySky-plugin/model/project/help/help.html');
 			// Output the screenshot as an image
  			await page.screenshot({ path: './plugins/zm-StarrySky-plugin/resource/img/help.png' });
 	 		await browser.close();
			//发送图像
			await this.reply(segment.image('file://'+pluginResources+'/img/help.png'))
		})();
		return false;
	}
	async zmStarrySkyState () 
	{
//图像操作
		//获取最新require函数方式
		const require = createRequire(import.meta.url);
		//获取puppeteer工具包
		const puppeteer = require('puppeteer');
		//帮助图像异步操作
		(async () => {
  			const browser = await puppeteer.launch();
  			const page = await browser.newPage();
			//确定网页规格
  			await page.setViewport({
				width: 1821,
				height: 3408
			});
			//html生成图
  			await page.goto('file:///E:/Redis-x64-5.0.14.1/Miao-Yunzai/plugins/zm-StarrySky-plugin/model/project/state/state.html');
 			// Output the screenshot as an image
  			await page.screenshot({ path: './plugins/zm-StarrySky-plugin/resource/img/state.png' });
 	 		await browser.close();
			//发送图像
			await this.reply(segment.image('file://'+pluginResources+'/img/state.png'))
		})();
		return false;
	}
}